import Mocks from "mockjs";
import moment from "moment";
import { iresponse, paramObj } from "../index";
import { memberList } from "./member";
console.log(memberList)
const getRealname = () => {
  return Mocks.mock({
    ["list|300"]: [
      {
        id: "@increment(1)",
        idCard: "@ID()",
        idName: "@cname()",
        created_time: "@date('yyyy-MM-dd')",
        updated_time: "@date('yyyy-MM-dd')",
        "type|1-5": 1,
        userId: "",
      },
    ],
  });
};

const realnameList = getRealname().list.map((v) => {
  v.userId = memberList[Math.floor(Math.random() * memberList.length)].user_id;
  return v;
});

const listurl = /\/api\/realname\/list(|\?\.*)/;
Mocks.mock(listurl, (config) => {
  const param = paramObj(config.url);
  const current = param.current ? param.current : 1;
  const pageSize = param.pageSize ? param.pageSize : 10;
  const start = (current - 1) * pageSize;
  const end = current * pageSize;
  const list = realnameList.slice(start, end);

  return iresponse({
    list,
    total: 300,
  });
});

const url = /\/api\/realname\/info(|\?\.*)/;
Mocks.mock(url, (config) => {
  const params = paramObj(config.url);
  console.log(params);
  const data = realnameList.find((v) => v.id == params.userId);
  return iresponse(data);
});
